package com.eric.demo.ringbuffer;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.util.DaemonThreadFactory;
import java.nio.ByteBuffer;

/**
 * @author guangyin.zhang
 * @since 2019/3/23
 */
public class LongEventMain {


    public static void main(String[] args) throws InterruptedException {
        LongEventFactory factory = new LongEventFactory();

        int bufferSize = 8;

        Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, bufferSize, DaemonThreadFactory.INSTANCE);

        disruptor.handleEventsWith(new LongEventHandler());

        disruptor.start();

        RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();

        LongEventProducerWithTranslator translator = new LongEventProducerWithTranslator(ringBuffer);
        ByteBuffer byteBuffer = ByteBuffer.allocate(8);

        for(long l =0;true;l++){
            byteBuffer.putLong(0, l);
            translator.onData(byteBuffer);
            System.out.println("Send Thread:" + Thread.currentThread().getName());
            Thread.sleep(100);
        }

    }




}
